﻿using HandyControl.Data;
using HandyControl.Themes;
using HandyControl.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace weighing
{
    /// <summary>
    /// 皮夫（主题） 助手
    /// </summary>
    public class SkinHelper
    {

       public static void Init()
        {
            if (GlobalData.Config.Skin != SkinType.Default)
            {
                UpdateSkin(GlobalData.Config.Skin);
            }
        }

        public static void UpdateSkin(SkinType skin)
        {
            SharedResourceDictionary.SharedDictionaries.Clear();
            var skins0 =((App)System.Windows.Application.Current)?.Resources?.MergedDictionaries[0];
            skins0?.MergedDictionaries.Clear();
            skins0?.MergedDictionaries.Add(ResourceHelper.GetSkin(skin));
            skins0?.MergedDictionaries.Add(ResourceHelper.GetSkin(typeof(App).Assembly, "Resources/Themes", skin));

            (System.Windows.Application.Current)?.MainWindow?.OnApplyTemplate();
        }

    }
}
